package jug.lodz.concurrency;

import java.util.Random;

public class Volatile1 {
	boolean variable;
	long counter;

	
	public static void main(String[] args) throws Exception {
		Volatile1 v = new Volatile1();
		Thread t = v.spawnNewThread();
		
		t.start();
		
		while (v.variable == false) {
			System.out.println(v.variable + " " + v.counter);
		}
		
	}

	private Thread spawnNewThread() {
		Thread t = new Thread(new Runnable() {
			@Override
			public void run() {
				boolean toggle = false;
				while (!isComplete()) {
					toggle = !toggle;
					counter++;
				}
			}
		});
		
		return t;
	}


	private boolean isComplete() {
		return variable;
	}


	private void complete() {
		variable = true;
	}

}
